Conditions | 2 |
Paths | 2 |
Total Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | if (typeof(PhpDebugBar) == 'undefined') { |
||
104 | handleFind: function(data) { |
||
105 | var self = this; |
||
106 | $.each(data, function(i, meta) { |
||
107 | var a = $('<a />') |
||
108 | .text('Load dataset') |
||
109 | .on('click', function(e) { |
||
110 | self.hide(); |
||
111 | self.load(meta['id'], function(data) { |
||
112 | self.callback(meta['id'], data); |
||
113 | }); |
||
114 | e.preventDefault(); |
||
115 | }); |
||
116 | |||
117 | var method = $('<a />') |
||
118 | .text(meta['method']) |
||
119 | .on('click', function(e) { |
||
120 | self.$table.empty(); |
||
121 | self.find({method: meta['method']}, 0, self.handleFind.bind(self)); |
||
122 | e.preventDefault(); |
||
123 | }); |
||
124 | |||
125 | var uri = $('<a />') |
||
126 | .text(meta['uri']) |
||
127 | .on('click', function(e) { |
||
128 | self.hide(); |
||
129 | self.load(meta['id'], function(data) { |
||
130 | self.callback(meta['id'], data); |
||
131 | }); |
||
132 | e.preventDefault(); |
||
133 | }); |
||
134 | |||
135 | var ip = $('<a />') |
||
136 | .text(meta['ip']) |
||
137 | .on('click', function(e) { |
||
138 | self.$table.empty(); |
||
139 | self.find({ip: meta['ip']}, 0, self.handleFind.bind(self)); |
||
140 | e.preventDefault(); |
||
141 | }); |
||
142 | |||
143 | var search = $('<a />') |
||
144 | .text('Show URL') |
||
145 | .on('click', function(e) { |
||
146 | self.$table.empty(); |
||
147 | self.find({uri: meta['uri']}, 0, self.handleFind.bind(self)); |
||
148 | e.preventDefault(); |
||
149 | }); |
||
150 | |||
151 | $('<tr />') |
||
152 | .append('<td>' + meta['datetime'] + '</td>') |
||
153 | .append('<td>' + meta['method'] + '</td>') |
||
154 | .append($('<td />').append(uri)) |
||
155 | .append($('<td />').append(ip)) |
||
156 | .append($('<td />').append(search)) |
||
157 | .appendTo(self.$table); |
||
158 | }); |
||
159 | if (data.length < this.get('items_per_page')) { |
||
160 | this.$loadmorebtn.hide(); |
||
161 | } |
||
162 | }, |
||
163 | |||
203 |